package apis

import (
	"k8sdev/pkg/services"
	"log"
	"net/http"

	"github.com/gin-gonic/gin"
	v1 "k8s.io/api/core/v1"
)

func GetNamespaces(c *gin.Context) {
	var (
		namespaces     []string
		namespacesList *[]v1.Namespace
		err            error
	)
	namespaces = make([]string, 0, 10)
	namespacesList, err = services.GetNamespaces()
	if err != nil {
		log.Fatal(err.Error())
		return
	}
	for _, item := range *namespacesList {
		namespaces = append(namespaces, item.Name)
	}
	c.JSON(http.StatusOK, gin.H{
		"namespaces": namespaces,
	})
}
